home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
com
/
othernet
/
fidonet
/
btnc200
/
btnc.c
next >
Wrap
C/C++ Source or Header
|
1996-09-10
|
10KB
|
524 lines
/*
** Program: BTNC
**
** Module: Main
*/
#include <portab.h>
#include <stdio.h>
#include <stdlib.h>
#include <tos.h>
#include <ext.h>
#include <aes.h>
#include <string.h>
#include <time.h>
#include <misclib.h>
#include "general.h"
#include "globals.h"
#include "messages.h"
#include "prototyp.h"
#include "logfile.h"
FILE *NodeList,
*AddList,
*PointList,
*nodeinfo_bnl,
*index_bnl,
*domains_bnl;
ULONG out;
#define BETA /* Dfini l'affichage version Bta */
VOID Display(VOID)
{
LOCAL UWORD lastreg;
if (!display || curreg == lastreg) return;
if (ap_displayed)
{
ALL_puts("\n");
ap_displayed = FALSE;
}
STD_puts("\r");
ALL_printf("Zone %3u, Region %4u", curaddr.zone, curreg);
LOG_puts("\n");
lastreg = curreg;
az_displayed = TRUE;
}
VOID WriteEntry(INDEX *idx, SYSTEM *sys)
{
static ULONG offset = 0L;
CSYSTEM sys_coded;
/*
** Write index entry
*/
if (c_format)
{
CINDEX newidx;
newidx.value = idx->value;
newidx.type = idx->type;
newidx.offset = offset;
fwrite(&newidx, sizeof(CINDEX), 1L, index_bnl);
/*
** Compress system entry
*/
CodeSystemEntry (sys, &sys_coded);
fwrite(&sys_coded, sys_coded.length, 1L, nodeinfo_bnl);
offset += sys_coded.length;
}
else
{
fwrite(idx, sizeof(INDEX), 1L, index_bnl);
fwrite(sys, sizeof(SYSTEM), 1L, nodeinfo_bnl);
}
out++;
}
WORD ProcessEntry(WORD type, BYTE *l, INDEX *idx, SYSTEM *sys, UWORD nl_lines)
{
memset(sys, 0, sizeof(SYSTEM));
return(ParseLine(type, l, idx, sys, nl_lines));
}
VOID ProcessPointlist(POINTLIST *pl)
{
BYTE NLline[256];
WORD error;
INDEX idx;
SYSTEM sys;
UWORD nl_lines = 0;
if (display)
{
STD_puts("\n");
ALL_printf("Adding pointlist '%s' to %u:%u/%u", pl->listfile,pl->boss.zone, pl->boss.net, pl->boss.node);
ap_displayed = TRUE;
}
PointList = fopen(pl->listfile, "r");
FOREVER
{
if (fgets(NLline, 255, PointList) == NULL) break;
nl_lines++;
if (*NLline == ';') continue;
if (*NLline == CTRL_Z) break;
if (!strchr(LEGAL_CHARS, *NLline))
{
ERR_printf("\nLine %u : First character '%c' is illegal\n", nl_lines, *NLline);
continue;
}
error = ProcessEntry(POINT, NLline, &idx, &sys, nl_lines);
sys.hubnode = 0;
if (!error) WriteEntry(&idx, &sys);
}
fclose(PointList);
}
VOID ProcessAddlist(ADDLIST *al)
{
BYTE NLline[256];
WORD error;
INDEX idx;
SYSTEM sys;
UWORD nl_lines = 0,
actnet;
struct ffblk FileRec;
doing_addlist = TRUE;
/* Modified ----------------------------- */
/*if ( (strnicmp(al->listfile, "POINTS24", 8L) == SUCCESS) */
if ( (strnicmp(al->listfile, "POINTS24", 8L) == SUCCESS)
|| ( al->new_3D_format==TRUE) )
points24 = TRUE;
/* -------------------------------------- */
/*
** Remember last net (needed to compile independant nodes in
** a region correctly
*/
actnet = curaddr.net;
if (findfirst(al->listfile, &FileRec, 0))
{
ERR_printf("\nNo matching file for %s !\n", al->listfile);
return;
}
AddList = fopen(FileRec.ff_name, "r");
/* Modified ----------------------- */
if( al->dimension4==TRUE)
{
ADDLIST4D=TRUE;
}
/* -------------------------------- */
if (display)
{
/* Modified ------------------------ */
/*printf("\nAdding 3D pointlist '%s'", FileRec.ff_name); */
if ( ADDLIST4D==TRUE)
{
STD_puts("\n");
ALL_printf("Adding 4D pointlist '%s'", FileRec.ff_name);
}
else if (al->new_3D_format==TRUE)
{
STD_puts("\n");
ALL_printf("Adding new format 3D pointlist '%s'", FileRec.ff_name);
}
else
{
STD_puts("\n");
ALL_printf("Adding 3D pointlist '%s'", FileRec.ff_name);
}
/* --------------------------------- */
ap_displayed = TRUE;
}
FOREVER
{
if (fgets(NLline, 255, AddList) == NULL) break;
nl_lines++;
if (*NLline == ';' ||
*NLline == 'Z' || *NLline == 'R') continue;
if (*NLline == CTRL_Z) break;
if (!strchr(LEGAL_CHARS, *NLline))
{
ERR_printf("\nLine %u : First character '%c' is illegal\n", nl_lines, *NLline);
continue;
}
error = ProcessEntry(NODE, NLline, &idx, &sys, nl_lines);
if (!error)
{
if (idx.type > HOST) continue;
WriteEntry(&idx, &sys);
}
}
curaddr.net = actnet;
fclose(AddList);
doing_addlist = FALSE;
points24 = FALSE;
/* Modified ----------------- */
ADDLIST4D=FALSE;
/* -------------------------- */
}
VOID DoPointlist(VOID)
{
POINTLIST *pl = pointlists;
while (pl)
{
if (curaddr.net == pl->boss.net &&
curaddr.node == pl->boss.node &&
curaddr.zone == pl->boss.zone)
ProcessPointlist(pl);
pl = pl->next;
}
}
VOID DoAddlist(UWORD region, UWORD zone)
{
ADDLIST *al = addlists;
while (al)
{
if (region == al->toregion &&
zone == al->tozone)
ProcessAddlist(al);
al = al->next;
}
}
VOID ProcessNodelist(DOMAIN *domain)
{
BYTE NLline[256];
INDEX idx;
SYSTEM sys;
WORD error;
UWORD nl_lines;
strcpy(NLline, domain->listfile);
strtok(NLline, ".");
/* Modified ---------------- */
/* if (display) */
if (display && *NLline)
/* ------------------------- */
{
ALL_printf("\n\n==================================================\n"
"Processing %s using %s of day #%s\n"
"==================================================\n\n",
domain->name, strtok(NLline, "."), strtok(NULL, "."));
az_displayed = FALSE;
}
onlyzone = domain->zone;
nl_lines = 0;
lastreg = 0;
FOREVER
{
if (fgets(NLline, 255, NodeList) == NULL) break;
nl_lines++;
if (*NLline == ';') continue;
if (*NLline == CTRL_Z) break;
if (!strchr(LEGAL_CHARS, *NLline))
{
ERR_printf("\nLine %u : First character '%c' is illegal\n", nl_lines, *NLline);
continue;
}
error = ProcessEntry(NODE, NLline, &idx, &sys, nl_lines);
if (!error || error == DOWN)
{
if (idx.type == RC)
{
if (lastreg && lastreg != curreg)
{
DoAddlist(lastreg, curaddr.zone);
lastreg = curreg;
}
else
lastreg = curreg;
/* Modified ---------------------- */
Display();
}
/* Display(); */
/* ------------------------------- */
WriteEntry(&idx, &sys);
if (error == DOWN)
down_nodes++;
else
active_nodes++;
DoPointlist();
}
else
{
if (error == ABORT) break;
}
}
if (lastreg)
DoAddlist(lastreg, curaddr.zone);
}
WORD main(WORD argc, BYTE **argv)
{
DOMAINSPEC *domain;
ULONG bufsize;
ULONG lastnodecount = 0;
time_t starttime;
puts(CopyrightMessage);
#ifdef ALPHA
puts(AlphaVersion);
#endif
#ifdef BETA
puts(BetaVersion);
#endif
starttime = time(NULL);
STD_printf("Parsing configuration file...\n");
ParseConfig(argc, argv);
if (!domains)
{
ALL_puts("\nNo domain(s) defined. Bye!\n");
return(FAILURE);
}
nodeinfo_bnl = fopen("NODEINFO.TMP", "wb");
index_bnl = fopen("INDEX.BNL", "wb");
domains_bnl = fopen("DOMAINS.BNL", "wb");
bufsize = ((ULONG)coreleft() - 128000UL) / 3L;
if (userlist)
{
fidouser_lst = fopen(userlist_name, "w");
setvbuf(fidouser_lst, NULL, _IOFBF, bufsize);
setvbuf(nodeinfo_bnl, NULL, _IOFBF, bufsize * 2UL);
}
else
setvbuf(nodeinfo_bnl, NULL, _IOFBF, bufsize * 3UL);
setvbuf(index_bnl, NULL, _IOFBF, 64000UL);
/*
** Hauptschleife
*/
domain = domains;
while (domain)
{
lastnodecount = out;
memset(hubphone, 0, 40);
domain->dat.startoffset = out * sizeof(INDEX);
NodeList = fopen(domain->dat.listfile, "r");
/* Modified ------------------------ */
/* ProcessNodelist(&domain->dat); */
/* fclose(NodeList); */
if(NodeList!=NULL)
{
ProcessNodelist(&domain->dat);
fclose(NodeList);
domain->dat.length = out - lastnodecount;
fwrite(&domain->dat, sizeof(DOMAIN), 1L, domains_bnl);
}
/* ----------------------------------*/
domain = domain->next;
}
/*
** Files schliessen
*/
/* Modified ---------------------------- */
if (userlist)
{
if( fflush(fidouser_lst)!=0 ) write_disk_error("fidouser.lst");
fclose(fidouser_lst);
}
if( fflush(domains_bnl)!=0 ) write_disk_error("domains.bnl");
fclose(domains_bnl);
if( fflush(index_bnl)!=0 ) write_disk_error("index.bnl");
fclose(index_bnl);
if( fflush(nodeinfo_bnl)!=0 ) write_disk_error("nodeinfo.bnl");
fclose(nodeinfo_bnl);
/* ------------------------------------- */
unlink("NODEINFO.BNL");
rename("NODEINFO.TMP", "NODEINFO.BNL");
/*
** Statistik ausgeben
*/
if (statistics)
{
ALL_puts("\n\n####################################\n");
ALL_puts("# Nodelist Output Statistics #\n");
ALL_puts("####################################\n");
ALL_puts("+----------------------------------+\n");
ALL_printf("| Total nodes processed | %5u |\n", active_nodes + down_nodes);
ALL_printf("| Active nodes | %5u |\n", active_nodes);
ALL_puts("+--------------------------+-------+\n");
ALL_printf("| Nodes down | %5u |\n", down_nodes);
ALL_printf("| Private nodes | %5u |\n", private_nodes);
ALL_puts("+--------------------------+-------+\n");
ALL_printf("| Zones | %5u |\n", zones);
ALL_printf("| Regions | %5u |\n", regions);
ALL_puts("+----------------------------------+\n\n");
ALL_printf("Required: %lu seconds.\n", time(NULL) - starttime);
}
/*
** Send Message
*/
{
BYTE *var,
*semperpath,
*hilf;
var = getenv("SEMPER");
semperpath = (var) ? strdup(var) : ".\\SEMPER\\";
if (semperpath && Last(semperpath) != '\\')
{
hilf = calloc(strlen(semperpath) + 1, sizeof(BYTE));
sprintf(hilf, "%s\\", semperpath);
free(semperpath);
semperpath = hilf;
}
SendAppMsg(semperpath, "READNIDX.SYS", "SEMPER ", FM_NLCOMPILER, SEMP_READ_NLIST);
}
logfile_close();
return(SUCCESS);
}
/* ---------------- EOF -------------------- */